package com.github.eclipseace.mybatis.pagination.dialect;

import org.apache.ibatis.session.RowBounds;

/**
 * @author eclipseAce
 */
public class MySqlPaginationDialect implements PaginationDialect {
	@Override
	public String wrapTotalQuery(String originalSql) {
		return new StringBuilder()
				.append("SELECT COUNT(*) FROM (")
				.append(originalSql)
				.append(") __subquery__")
				.toString();
	}

	@Override
	public String wrapPageQuery(String originalSql, RowBounds rowBounds) {
		return new StringBuilder()
				.append("SELECT * FROM (")
				.append(originalSql)
				.append(") LIMIT ")
				.append(rowBounds.getOffset())
				.append(",")
				.append(rowBounds.getLimit())
				.toString();
	}
}
